# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'PassportDIY.ui'
#
# Created: Fri Jul 30 11:57:41 2010
#      by: PyQt4 UI code generator 4.7.4
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
from PassportView import PassportView
from ConfigLoader import ConfigLoader
from PhotoConfig import PhotoConfig,  PhotoSize
import os
import glob

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        #MainWindow.resize(800, 580)
        MainWindow.setFixedSize(QtCore.QSize(800, 600))
        self.cwd = os.getcwd().replace("\\", "/")
        self.centralwidget = QtGui.QWidget(MainWindow)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(40)
        sizePolicy.setVerticalStretch(40)
        sizePolicy.setHeightForWidth(self.centralwidget.sizePolicy().hasHeightForWidth())
        self.centralwidget.setSizePolicy(sizePolicy)
        self.centralwidget.setObjectName("centralwidget")
        self.horizontalLayout_3 = QtGui.QHBoxLayout(self.centralwidget)
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.horizontalLayout_2 = QtGui.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.verticalLayout_3 = QtGui.QVBoxLayout()
        self.verticalLayout_3.setObjectName("verticalLayout_3")
        self.gridLayout_2 = QtGui.QGridLayout()
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.label_4 = QtGui.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setWeight(75)
        font.setBold(True)
        self.label_4.setFont(font)
        self.label_4.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.label_4.setObjectName("label_4")
        self.gridLayout_2.addWidget(self.label_4, 0, 0, 1, 1)
        self.listCountry = QtGui.QComboBox(self.centralwidget)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.listCountry.sizePolicy().hasHeightForWidth())
        self.listCountry.setSizePolicy(sizePolicy)
        self.listCountry.setMinimumSize(QtCore.QSize(0, 0))
        self.listCountry.setObjectName("listCountry")
        self.gridLayout_2.addWidget(self.listCountry, 0, 1, 1, 1)
        self.label_5 = QtGui.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setWeight(75)
        font.setBold(True)
        self.label_5.setFont(font)
        self.label_5.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.label_5.setObjectName("label_5")
        self.gridLayout_2.addWidget(self.label_5, 1, 0, 1, 1)
        self.listPhotoType = QtGui.QComboBox(self.centralwidget)
        self.listPhotoType.setObjectName("listPhotoType")
        self.gridLayout_2.addWidget(self.listPhotoType, 1, 1, 1, 1)
        self.verticalLayout_3.addLayout(self.gridLayout_2)
        spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
        self.verticalLayout_3.addItem(spacerItem)
        self.gridLayout_3 = QtGui.QGridLayout()
        self.gridLayout_3.setObjectName("gridLayout_3")
        self.label_2 = QtGui.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setWeight(75)
        font.setBold(True)
        self.label_2.setFont(font)
        self.label_2.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.label_2.setObjectName("label_2")
        self.gridLayout_3.addWidget(self.label_2, 0, 0, 1, 1)
        self.txtWidth = QtGui.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setWeight(75)
        font.setBold(True)
        self.txtWidth.setFont(font)
        self.txtWidth.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.txtWidth.setObjectName("txtWidth")
        self.gridLayout_3.addWidget(self.txtWidth, 0, 1, 1, 1)
        self.label_3 = QtGui.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setWeight(75)
        font.setBold(True)
        self.label_3.setFont(font)
        self.label_3.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.label_3.setObjectName("label_3")
        self.gridLayout_3.addWidget(self.label_3, 1, 0, 1, 1)
        self.txtHeight = QtGui.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setWeight(75)
        font.setBold(True)
        self.txtHeight.setFont(font)
        self.txtHeight.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.txtHeight.setObjectName("txtHeight")
        self.gridLayout_3.addWidget(self.txtHeight, 1, 1, 1, 1)
        spacerItem1 = QtGui.QSpacerItem(20, 150, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
        self.gridLayout_3.addItem(spacerItem1, 4, 0, 1, 1)
        self.btnSave4R = QtGui.QPushButton(self.centralwidget)
        self.btnSave4R.setObjectName("btnSave4R")
        self.gridLayout_3.addWidget(self.btnSave4R, 3, 1, 1, 1)
        self.btnSaveOne = QtGui.QPushButton(self.centralwidget)
        self.btnSaveOne.setObjectName("btnSaveOne")
        self.gridLayout_3.addWidget(self.btnSaveOne, 3, 0, 1, 1)
        spacerItem2 = QtGui.QSpacerItem(20, 80, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
        self.gridLayout_3.addItem(spacerItem2, 2, 0, 1, 1)
        self.verticalLayout_3.addLayout(self.gridLayout_3)
        self.gridLayout = QtGui.QGridLayout()
        self.gridLayout.setObjectName("gridLayout")
        self.btnMoveUp = QtGui.QToolButton(self.centralwidget)
        self.btnMoveUp.setIcon(QtGui.QIcon(self.cwd + '/image/up.png'))
        self.btnMoveUp.setIconSize(QtCore.QSize(32, 32))
        self.btnMoveUp.setObjectName("btnMoveUp")
        self.gridLayout.addWidget(self.btnMoveUp, 0, 1, 1, 1)
        self.btnMoveLeft = QtGui.QToolButton(self.centralwidget)
        self.btnMoveLeft.setIcon(QtGui.QIcon(self.cwd + '/image/left.png'))
        self.btnMoveLeft.setIconSize(QtCore.QSize(32, 32))
        self.btnMoveLeft.setObjectName("btnMoveLeft")
        self.gridLayout.addWidget(self.btnMoveLeft, 1, 0, 1, 1)
        self.btnMoveDown = QtGui.QToolButton(self.centralwidget)
        self.btnMoveDown.setIcon(QtGui.QIcon(self.cwd + '/image/down.png'))
        self.btnMoveDown.setIconSize(QtCore.QSize(32, 32))
        self.btnMoveDown.setObjectName("btnMoveDown")
        self.gridLayout.addWidget(self.btnMoveDown, 2, 1, 1, 1)
        self.btnMoveRight = QtGui.QToolButton(self.centralwidget)
        self.btnMoveRight.setIcon(QtGui.QIcon(self.cwd + '/image/right.png'))
        self.btnMoveRight.setIconSize(QtCore.QSize(32, 32))
        self.btnMoveRight.setObjectName("btnMoveRight")
        self.gridLayout.addWidget(self.btnMoveRight, 1, 2, 1, 1)
        self.verticalLayout_3.addLayout(self.gridLayout)
        spacerItem3 = QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
        self.verticalLayout_3.addItem(spacerItem3)
        self.horizontalLayout_2.addLayout(self.verticalLayout_3)
        self.groupBox = QtGui.QGroupBox(self.centralwidget)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.groupBox.sizePolicy().hasHeightForWidth())
        self.groupBox.setSizePolicy(sizePolicy)
        self.groupBox.setFlat(False)
        self.groupBox.setObjectName("groupBox")
        self.verticalLayout_2 = QtGui.QVBoxLayout(self.groupBox)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.widget = QtGui.QWidget(self.groupBox)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.widget.sizePolicy().hasHeightForWidth())
        self.widget.setSizePolicy(sizePolicy)
        self.widget.setMinimumSize(QtCore.QSize(400, 400))
        self.widget.setObjectName("widget")
        self.verticalLayout_4 = QtGui.QVBoxLayout(self.widget)
        self.verticalLayout_4.setSpacing(0)
        self.verticalLayout_4.setMargin(0)
        self.verticalLayout_4.setObjectName("verticalLayout_4")
        self.photoScene = QtGui.QGraphicsScene()
        self.photoView = PassportView(self.photoScene)
        self.photoView.setFixedSize(644, 484)
        self.photoView.setObjectName("photoView")
        self.verticalLayout_4.addWidget(self.photoView)
        self.verticalLayout_2.addWidget(self.widget)
        self.verticalLayout = QtGui.QVBoxLayout()
        self.verticalLayout.setObjectName("verticalLayout")
        self.line = QtGui.QFrame(self.groupBox)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.line.sizePolicy().hasHeightForWidth())
        self.line.setSizePolicy(sizePolicy)
        self.line.setMinimumSize(QtCore.QSize(500, 10))
        self.line.setFrameShape(QtGui.QFrame.HLine)
        self.line.setFrameShadow(QtGui.QFrame.Sunken)
        self.line.setObjectName("line")
        self.verticalLayout.addWidget(self.line)
        self.horizontalLayout = QtGui.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.btnZoomOut = QtGui.QToolButton(self.groupBox)
        self.btnZoomOut.setIconSize(QtCore.QSize(32, 32))
        self.btnZoomOut.setIcon(QtGui.QIcon(self.cwd + '/image/minus.png'))
        self.btnZoomOut.setObjectName("btnZoomOut")
        self.horizontalLayout.addWidget(self.btnZoomOut)
        self.zoomSlider = QtGui.QSlider(self.groupBox)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.zoomSlider.sizePolicy().hasHeightForWidth())
        self.zoomSlider.setSizePolicy(sizePolicy)
        self.zoomSlider.setMinimumSize(QtCore.QSize(250, 0))
        self.zoomSlider.setMinimum(1)
        self.zoomSlider.setMaximum(100)
        self.zoomSlider.setOrientation(QtCore.Qt.Horizontal)
        self.zoomSlider.setTickPosition(QtGui.QSlider.NoTicks)
        self.zoomSlider.setObjectName("zoomSlider")
        self.horizontalLayout.addWidget(self.zoomSlider)
        self.zoomValue = QtGui.QSpinBox(self.groupBox)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.zoomValue.sizePolicy().hasHeightForWidth())
        self.zoomValue.setSizePolicy(sizePolicy)
        self.zoomValue.setMinimum(1)
        self.zoomValue.setMaximum(100)
        self.zoomValue.setObjectName("zoomValue")
        self.horizontalLayout.addWidget(self.zoomValue)
        self.btnZoomIn = QtGui.QToolButton(self.groupBox)
        self.btnZoomIn.setIconSize(QtCore.QSize(32, 32))
        self.btnZoomIn.setIcon(QtGui.QIcon(self.cwd + '/image/plus.png'))
        self.btnZoomIn.setObjectName("btnZoomIn")
        self.horizontalLayout.addWidget(self.btnZoomIn)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.verticalLayout_2.addLayout(self.verticalLayout)
        self.horizontalLayout_2.addWidget(self.groupBox)
        self.horizontalLayout_3.addLayout(self.horizontalLayout_2)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 18))
        self.menubar.setObjectName("menubar")
        self.menu_File = QtGui.QMenu(self.menubar)
        self.menu_File.setObjectName("menu_File")
        self.menu_Help = QtGui.QMenu(self.menubar)
        self.menu_Help.setObjectName("menu_Help")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.menuOpen = QtGui.QAction(MainWindow)
        self.menuOpen.setObjectName("menuOpen")
        self.menuExit = QtGui.QAction(MainWindow)
        self.menuExit.setObjectName("menuExit")
        self.menuAbout = QtGui.QAction(MainWindow)
        self.menuAbout.setObjectName("menuAbout")
        self.menu_File.addAction(self.menuOpen)
        self.menu_File.addAction(self.menuExit)
        self.menu_Help.addAction(self.menuAbout)
        self.menubar.addAction(self.menu_File.menuAction())
        self.menubar.addAction(self.menu_Help.menuAction())
        self.label_4.setBuddy(self.listCountry)
        self.label_5.setBuddy(self.listPhotoType)

        self.retranslateUi(MainWindow)
        self.setupConfig()
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        MainWindow.setTabOrder(self.listCountry, self.listPhotoType)
        MainWindow.setTabOrder(self.listPhotoType, self.btnSaveOne)
        MainWindow.setTabOrder(self.btnSaveOne, self.btnSave4R)
        MainWindow.setTabOrder(self.btnSave4R, self.btnMoveUp)
        MainWindow.setTabOrder(self.btnMoveUp, self.btnMoveDown)
        MainWindow.setTabOrder(self.btnMoveDown, self.btnMoveLeft)
        MainWindow.setTabOrder(self.btnMoveLeft, self.btnMoveRight)
        MainWindow.setTabOrder(self.btnMoveRight, self.btnZoomIn)
        MainWindow.setTabOrder(self.btnZoomIn, self.btnZoomOut)
        
    def setupConfig(self):
        cfg_dir = self.cwd + "/config/"
        chain = cfg_dir + "*.xml"
        files = glob.glob(chain)
        files.sort(cmp=lambda x, y: cmp(x.lower(), y.lower()))
        idx = selected = 0
        self.listCountry.clear()
        for file in files:
            path,  name = os.path.split(file)
            data,  ext = os.path.splitext(name)
            self.listCountry.addItem(data)
            if data.lower() == "singapore":
                selected = idx
            idx = idx + 1
        self.listCountry.setCurrentIndex(selected)
        file = cfg_dir + str(self.listCountry.currentText()) + ".xml"
        self.cfg_list = ConfigLoader(file).GetConfigs()
        self.listPhotoType.clear()
        for cfg in self.cfg_list:
            self.listPhotoType.addItem(cfg.name)
        self.listPhotoType.setCurrentIndex(0)
        self.updateLabel()

    def updateLabel(self):
        idx = self.listPhotoType.currentIndex()
        self.cfg = self.cfg_list[idx]
        if self.cfg.unit == self.cfg.UNIT_PIX:
            unit = "pix"
        elif self.cfg.unit == self.cfg.UNIT_INCH:
            unit = "inch"
        elif self.cfg.unit == self.cfg.UNIT_CM:
            unit = "cm"
        self.txtWidth.setText(str(self.cfg.size.width()) + " " + unit)
        self.txtHeight.setText(str(self.cfg.size.height()) + " " + unit)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "Passport DIY", None, QtGui.QApplication.UnicodeUTF8))
        self.label_4.setText(QtGui.QApplication.translate("MainWindow", "Country:", None, QtGui.QApplication.UnicodeUTF8))
        self.label_5.setText(QtGui.QApplication.translate("MainWindow", "Type:", None, QtGui.QApplication.UnicodeUTF8))
        self.label_2.setText(QtGui.QApplication.translate("MainWindow", "width:", None, QtGui.QApplication.UnicodeUTF8))
        self.txtWidth.setText(QtGui.QApplication.translate("MainWindow", "0 cm", None, QtGui.QApplication.UnicodeUTF8))
        self.label_3.setText(QtGui.QApplication.translate("MainWindow", "height:", None, QtGui.QApplication.UnicodeUTF8))
        self.txtHeight.setText(QtGui.QApplication.translate("MainWindow", "0 cm", None, QtGui.QApplication.UnicodeUTF8))
        self.btnSave4R.setText(QtGui.QApplication.translate("MainWindow", "Save 4R", None, QtGui.QApplication.UnicodeUTF8))
        self.btnSaveOne.setText(QtGui.QApplication.translate("MainWindow", "Save One", None, QtGui.QApplication.UnicodeUTF8))
        self.btnMoveUp.setText(QtGui.QApplication.translate("MainWindow", "Up", None, QtGui.QApplication.UnicodeUTF8))
        self.btnMoveLeft.setText(QtGui.QApplication.translate("MainWindow", "Left", None, QtGui.QApplication.UnicodeUTF8))
        self.btnMoveDown.setText(QtGui.QApplication.translate("MainWindow", "Down", None, QtGui.QApplication.UnicodeUTF8))
        self.btnMoveRight.setText(QtGui.QApplication.translate("MainWindow", "Right", None, QtGui.QApplication.UnicodeUTF8))
        self.btnZoomOut.setText(QtGui.QApplication.translate("MainWindow", "Zoom Out", None, QtGui.QApplication.UnicodeUTF8))
        self.zoomValue.setSuffix(QtGui.QApplication.translate("MainWindow", "%", None, QtGui.QApplication.UnicodeUTF8))
        self.btnZoomIn.setText(QtGui.QApplication.translate("MainWindow", "Zoom In", None, QtGui.QApplication.UnicodeUTF8))
        self.menu_File.setTitle(QtGui.QApplication.translate("MainWindow", "&File", None, QtGui.QApplication.UnicodeUTF8))
        self.menu_Help.setTitle(QtGui.QApplication.translate("MainWindow", "&Help", None, QtGui.QApplication.UnicodeUTF8))
        self.menuOpen.setText(QtGui.QApplication.translate("MainWindow", "&Open", None, QtGui.QApplication.UnicodeUTF8))
        self.menuExit.setText(QtGui.QApplication.translate("MainWindow", "&Exit", None, QtGui.QApplication.UnicodeUTF8))
        self.menuAbout.setText(QtGui.QApplication.translate("MainWindow", "&About", None, QtGui.QApplication.UnicodeUTF8))
